package JackSu.常用类.字符串.exer;

import org.junit.Test;

public class _反转字符串中的指定部分 {
    @Test
    public void reserve(){

       String str="abcdefg";
        char[] chars = str.substring(2, 6).toCharArray();
        String s = str.substring(2, 6);
        int len=chars.length;
        if (len %2==0) {
            len=len/2-1;
        }else {
            len=(len-1)/2-1;
        }
        for (int i = 0; i <=len; i++) {
            char temp = '0';
        temp=chars[i];
          chars[i]=chars[chars.length-1-i];
          chars[chars.length-1-i]=temp;

        }
        //字符串实际还是对象 可以通过构造方法转换把字符数组转换
       str= str.replace(s,new String(chars));
        System.out.println(str);


    }

}
